package cn.cnhis.online.activity.login.model;

import android.util.Log;

import com.google.gson.JsonObject;

import org.json.JSONObject;

import java.io.InputStream;
import java.util.Map;

import cn.cnhis.online.BuildConfig;
import cn.cnhis.online.activity.login.contract.ILoginContract;
import cn.cnhis.online.base.DefaultDisposablePoolImpl;
import cn.cnhis.online.mymodule.HttpController;
import io.reactivex.internal.observers.BlockingBaseObserver;
import okhttp3.ResponseBody;

/**
 * @author 刘祥龙
 * @describe
 * @date 2020/2/27  17:16
 * - generate by MvpAutoCodePlus plugin.
 */

public class LoginModel extends DefaultDisposablePoolImpl implements ILoginContract.Model {

    @Override
    public void login(Map<String, String> map, ILoginContract.View view) {
        HttpController.mobileLogin(map, new BlockingBaseObserver<Map>() {
            @Override
            public void onNext(Map map) {
                view.login(map);
            }

            @Override
            public void onError(Throwable e) {
                if (BuildConfig.DEBUG) Log.d("LoginModel", "e:" + e);
                view.showErr("登录失败,请重试！");
            }
        });
    }


    @Override
    public void getCode(ILoginContract.View view) {
        HttpController.getVerification(null, new BlockingBaseObserver<ResponseBody>() {
            @Override
            public void onNext(ResponseBody map) {
                view.getCode(map);
            }

            @Override
            public void onError(Throwable e) {
                if (BuildConfig.DEBUG) Log.d("LoginModel", "e:" + e);
                view.showErr("验证码发送失败！");
            }
        });
    }

    @Override
    public void getLogo(ILoginContract.View view) {
        HttpController.getLogo(null, new BlockingBaseObserver<Map>() {
            @Override
            public void onNext(Map map) {
                view.getLogo(map);
            }

            @Override
            public void onError(Throwable e) {
                if (BuildConfig.DEBUG) Log.d("LoginModel", "e:" + e);
                view.showErr("获取logo失败！");
            }
        });
    }

    @Override
    public void getMenuShowColor(ILoginContract.View view) {
        HttpController.getMenuShowColor(null, new BlockingBaseObserver<Map>() {
            @Override
            public void onNext(Map map) {
                view.getMenuShowColor(map);
            }

            @Override
            public void onError(Throwable e) {
                if (BuildConfig.DEBUG) Log.d("LoginModel", "e:" + e);
                view.showErr("服务异常请联系管理员！");
            }
        });
    }

    @Override
    public void getAppActiveMqInfo(ILoginContract.View view) {
        HttpController.getAppActiveMqInfo(null, new BlockingBaseObserver<Map>() {
            @Override
            public void onNext(Map map) {
                view.getAppActiveMqInfo(map);
            }

            @Override
            public void onError(Throwable e) {
                if (BuildConfig.DEBUG) Log.d("LoginModel", "e:" + e);
                view.showErr("服务异常请联系管理员！");
            }
        });
    }
}

